<?php
/**
 * File: Index.php
 * User: Mr.Yang
 * Date: 2025/3/19 0019
 * Time: 10:20
 * Note:
 */

namespace app\home\controller;


use app\admin\model\Book;
use app\admin\model\Category;

class Index extends Base
{
    /**
     * Note: 首页
     * User: Mr.Yang
     * @return mixed
     */
    public function index()
    {
        //获取所有分类
        $category = Category::where("is_show", "=", 1)->order('sort', 'asc')->select()->toArray();
        foreach ($category as $k => $v) {
            $books = Book::where([['catid', '=', $v['id']], ['status', '=', 1]])->order('id', 'desc')->limit(8)->select()->toArray();
            $category[$k]['books'] = $books;
        }
        $this->assign('category', $category);
        return $this->fetch();
    }
}